Skip to content

mem: Allow overriding the default buffer pool.#8806

Merged
easwars merged 6 commits intogrpc:masterfrom
vanja-p:vanja-bufpool
Jan 20, 2026
Merged

mem: Allow overriding the default buffer pool.#8806
easwars merged 6 commits intogrpc:masterfrom
vanja-p:vanja-bufpool

Conversation

@vanja-p
Copy link
Contributor

@vanja-p vanja-p commented Jan 6, 2026

The default buffer pool only has a only a few tiers, which hurts performance in some applications. In #8770, it was decided that instead of adding more tiers to the default pool, we should allow changing the default pool.

RELEASE NOTES:

  • mem: Allow changing the default buffer pool

The default buffer pool only has a only a few tiers, which hurts performance in some applications. In, it was decided that instead of adding more tiers to the default pool, we should allow changing the default pool.
@vanja-p
Copy link
Contributor Author

vanja-p commented Jan 6, 2026

I didn't know if you internal.SetDefaultBufferPool should be moved from internal/internal.go to internal/experimental.go so I kept it as is for now.

@vanja-p vanja-p changed the title Allow overriding the default buffer pool. mem: Allow overriding the default buffer pool. Jan 6, 2026
@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.00%. Comparing base (bccbb10) to head (03954f1).
⚠️ Report is 24 commits behind head on master.

Files with missing lines Patch % Lines
experimental/experimental.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8806      +/-   ##
==========================================
- Coverage   83.30%   83.00%   -0.31%     
==========================================
  Files         418      414       -4     
  Lines       33004    32779     -225     
==========================================
- Hits        27493    27207     -286     
- Misses       4102     4115      +13     
- Partials     1409     1457      +48     
Files with missing lines Coverage Δ
internal/internal.go 50.00% <ø> (-10.00%) ⬇️
internal/leakcheck/leakcheck.go 90.04% <100.00%> (ø)
mem/buffer_pool.go 96.61% <100.00%> (ø)
experimental/experimental.go 25.00% <0.00%> (-8.34%) ⬇️

... and 42 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vanja-p
Copy link
Contributor Author

vanja-p commented Jan 6, 2026

I can't figure out how to get the PR validation to pass. My initial PR title didn't start with "mem:", but now it does.

@eshitachandwani eshitachandwani added the Type: Performance Performance improvements (CPU, network, memory, etc) label Jan 7, 2026
@eshitachandwani eshitachandwani added this to the 1.79 Release milestone Jan 7, 2026
@eshitachandwani
Copy link
Member

@vanja-p can you check if the test failing is related to the changes or not?
https://github.com/grpc/grpc-go/actions/runs/20763701462/job/59624817820?pr=8806

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vanja-p
Copy link
Contributor Author

vanja-p commented Jan 7, 2026

@vanja-p can you check if the test failing is related to the changes or not? https://github.com/grpc/grpc-go/actions/runs/20763701462/job/59624817820?pr=8806

@eshitachandwani, looks like it's not related to my change. Rerunning them passed, and also, my 2 new lines don't have any coverage.

@eshitachandwani eshitachandwani assigned arjan-bal and unassigned vanja-p Jan 13, 2026
@arjan-bal
Copy link
Contributor

I didn't know if you internal.SetDefaultBufferPool should be moved from internal/internal.go to internal/experimental.go so I kept it as is for now.

I think it's better to move SetDefaultBufferPool to the internal/experimental.go file to maintain consistency with other non-test functions exposed by the mem package. Otherwise, LGTM.

@arjan-bal arjan-bal self-requested a review January 13, 2026 07:09
@arjan-bal arjan-bal assigned vanja-p and unassigned arjan-bal Jan 13, 2026
@arjan-bal arjan-bal added the Area: RPC Features Includes Compression, Encoding, Attributes/Metadata, Interceptors. label Jan 13, 2026
@vanja-p
Copy link
Contributor Author

vanja-p commented Jan 15, 2026

I think it's better to move SetDefaultBufferPool to the internal/experimental.go file to maintain consistency with other non-test functions exposed by the mem package. Otherwise, LGTM.

Done.

Copy link
Contributor

@arjan-bal arjan-bal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor comment; otherwise, LGTM. Adding a second reviewer.

// can't be changed otherwise. The provided buffer pool must be non-nil. This
// must be called before creating any grpc clients or servers. The default value
// is mem.DefaultBufferPool.
func SetDefaultBufferPool(bufferPool mem.BufferPool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of requiring users to set this before making RPCs, we recommend calling these functions within an init() function. This prevents data races that can occur when multiple packages invoke the same method simultaneously. For example, the balancer.Register function includes the following requirement:

NOTE: this function must only be called during initialization time (i.e., in an init() function) and is not thread-safe...

Can you please add a similar note here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, done.

@arjan-bal arjan-bal assigned easwars and unassigned vanja-p Jan 16, 2026
@arjan-bal arjan-bal requested a review from easwars January 16, 2026 06:20
defaultPool := mem.DefaultBufferPool()
globalPool.Store(&defaultPool)
(internal.SetDefaultBufferPoolForTesting.(func(mem.BufferPool)))(&globalPool)
(internal.SetDefaultBufferPool.(func(mem.BufferPool)))(&globalPool)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can the extra parenthesis be avoided? Can this be
internal.SetDefaultBufferPool.(func(mem.BufferPool))(&globalPool) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. done.

@easwars easwars removed their assignment Jan 20, 2026
@easwars easwars merged commit bb2073d into grpc:master Jan 20, 2026
14 checks passed
@vanja-p vanja-p deleted the vanja-bufpool branch January 20, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: RPC Features Includes Compression, Encoding, Attributes/Metadata, Interceptors. Type: Performance Performance improvements (CPU, network, memory, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants